
import { defineStore } from 'pinia'

export const UseTabsStore = defineStore('Tabs', {
    state: () => {
        return {
            Mapping: {},
            ActiveKey: ''
        }
    },
    getters: {

    },
    actions: {
        SetMapping(key, value) {
            this.Mapping[key] = value;
        },
        DeleteMapping(delKey) {
            const pathArray = Object.keys(this.Mapping);
            if (pathArray.length == 1 && pathArray[0] == import.meta.env.VITE_TAB_DEFAULT_PATH) {
                return undefined
            }
            const keyIndex = pathArray.indexOf(delKey);
            delete this.Mapping[delKey];
            pathArray.splice(keyIndex, 1);
            if (pathArray[keyIndex - 1]) {
                return pathArray[keyIndex - 1]
            } else if (pathArray[0]) {
                return pathArray[0]
            } else {
                return undefined
            }
        },
        clear() {
            this.Mapping = {};
            this.ActiveKey = '';
        }
    },
})